home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / INIT.programming-tips / doubleCR.1 < prev   
Encoding:
Text File  |  1990-05-08  |  3.2 KB  |  104 lines

  1. #include <asm.h>
  2. #include <Quickdraw.h>
  3. #include <MemoryMgr.h>
  4. #include <EventMgr.h>
  5.  
  6. #define Chk(x) ((x) << 1 ^ 0x1021)
  7. #define KeyCode(x,y) (BitTst(&(x), (y) ^ 0x07))
  8. #define True (1)
  9. #define False (0)
  10.  
  11. extern int icnVert : 0x928;
  12. extern int icnVChk : 0x92a;
  13. extern int icnHorz : 0x92c;
  14. extern int icnHChk : 0x92e;
  15. GrafPtr myPort;
  16.  
  17. main()
  18. {
  19.     KeyMap myKMap;
  20.     ResType rType;
  21.     Str255 name;
  22.     void (*p)();
  23.     THz myZone;
  24.     int i, id;
  25.     Handle h;
  26.  
  27.     myPort = (GrafPtr) NewPtr(sizeof(GrafPort));
  28.     OpenPort(myPort);
  29.     GetKeys(&myKMap);
  30.     if (!Button() && !KeyCode(myKMap, 56))
  31.         for (i = Count1Resources('code'); i > 0; --i) {
  32.             if (h = Get1IndResource('code', i)) {
  33.                 asm {
  34.             move.l        h,                a0
  35.             _GetHandleSize
  36.             move.w        d0,               id
  37.             _NewPtr       SYS
  38.             move.l        a0,               p
  39.                 }
  40.                 BlockMove(*h, (Ptr) p, id);
  41.                 GetResInfo(h, &id, &rType, name);
  42.                 ReleaseResource(h);
  43.                 (*p)();        /*  Call code for startup  */
  44.                 DrawIcon(id, True);
  45.             }
  46.         }
  47.     else DrawIcon(127, True);
  48.     ClosePort(myPort);
  49.     DisposPtr((Ptr) myPort);
  50. }
  51.  
  52. /*  This routines plots an icon onto the desktop.  The variable 'icon'    */
  53. /*  holds an ID number of the ICN# resource to be plotted to the screen    */
  54. /*  and doInc is a flag that will make the next icon to be plotted,    */
  55. /*  plotted either on top of the last icon or next to the last icon.    */
  56. /*  This allows for 'animation sequences' if wanted.  Other features    */
  57. /*  are: 'autowrap' or wrapping to the previous line when icon will be    */
  58. /*  plotted off the right hand side of the screen.  This procedure    */
  59. /*  should be compatable with most previous ShowIcon algorithms.    */
  60.  
  61. DrawIcon(icon, doInc)
  62. int icon,
  63.     doInc;
  64. {
  65.     BitMap data, mask;
  66.     Handle h;
  67.     Rect dst;
  68.  
  69.     if (h = GetResource('ICN#', icon)) {
  70.         if (Chk(icnVert) != icnVChk)
  71.             icnVChk = Chk(icnVert = myPort->portBits.bounds.bottom - 40);
  72.         if (Chk(icnHorz) != icnHChk)
  73.             icnHChk = Chk(icnHorz = 8);
  74.         if (icnHorz > myPort->portBits.bounds.right - 32) {
  75.             icnHChk = Chk(icnHorz = 8);
  76.             icnVChk = Chk(icnVert -= 40);
  77.         }
  78.         HLock(h);
  79.         data.baseAddr = *h;
  80.         mask.baseAddr = *h + 0x80;
  81.         data.rowBytes = 4;
  82.         mask.rowBytes = 4;
  83.         SetRect(&data.bounds, 0, 0, 32, 32);
  84.         SetRect(&mask.bounds, 0, 0, 32, 32);
  85.         SetRect(&dst, icnHorz, icnVert, icnHorz + 32, icnVert + 32);
  86.         CopyMask(&data, &mask, &myPort->portBits, &data.bounds,
  87.                  &mask.bounds, &dst);
  88.         ReleaseResource(h);
  89.         if (doInc) icnHChk = Chk(icnHorz += 40);
  90.     }
  91. }
  92. --
  93.  
  94. +--------------------------------------------------------------------+
  95. | From the Macintosh of: Kevin L. Sitze. This is ME: ksitze@NMSU.edu |
  96. +------------------------------------------------------+-------------+
  97. | The difference between intelligence and stupidity is |   Is this   |
  98. | that intelligence has a limit.          -- anonymous |   better?   |
  99. +------------------------------------------------------+-------------+
  100.  
  101.  
  102.  
  103.  
  104. ˇ